#include <iostream>
#include <cstdio>
using namespace std;

int f[100005], l[100005], t[100005], ne[100005], o[100005][3], ans[100005];
int n, m, q, sum, tot;
bool p[1005][1005];

void insert(int x, int y)
{
	t[++tot] = y;
	ne[tot] = l[x];
	l[x] = tot;
}

void dfs(int x)
{
	if (x != 0)
	{
		switch (o[x][0])
		{
		case 1:
		{
			sum -= p[o[x][1]][o[x][2]];
			p[o[x][1]][o[x][2]] ^= 1;
			sum += p[o[x][1]][o[x][2]];
			break;
		}
		case 2:
		{
			for (int c = 1; c <= m; c++)
			{
				sum -= p[o[x][1]][c];
				p[o[x][1]][c] ^= 1;
				sum += p[o[x][1]][c];
			}
			break;
		}
		case 3:
		{
			for (int r = 1; r <= n; r++)
			{
				sum -= p[r][o[x][1]];
				p[r][o[x][1]] ^= 1;
				sum += p[r][o[x][1]];
			}
			break;
		}
		}
		ans[x] = sum;
	}
	for (int i = l[x]; i != 0; i = ne[i])
		dfs(t[i]);
	if (x != 0)
	{
		switch (o[x][0])
		{
		case 1:
		{
			sum -= p[o[x][1]][o[x][2]];
			p[o[x][1]][o[x][2]] ^= 1;
			sum += p[o[x][1]][o[x][2]];
			break;
		}
		case 2:
		{
			for (int c = 1; c <= m; c++)
			{
				sum -= p[o[x][1]][c];
				p[o[x][1]][c] ^= 1;
				sum += p[o[x][1]][c];
			}
			break;
		}
		case 3:
		{
			for (int r = 1; r <= n; r++)
			{
				sum -= p[r][o[x][1]];
				p[r][o[x][1]] ^= 1;
				sum += p[r][o[x][1]];
			}
			break;
		}
		}
	}
}

void solve()
{
	for (int i = 1, op, x, y; i <= q; i++)
	{
		scanf("%d%d", &op, &x);
		switch (op)
		{
		case 1:
		{
			scanf("%d", &y);
			f[i] = i - 1;
			insert(i - 1, i);
			o[i][0] = 1;
			o[i][1] = x;
			o[i][2] = y;
			break;
		}
		case 2:
		{
			f[i] = i - 1;
			insert(i - 1, i);
			o[i][0] = 2;
			o[i][1] = x;
			break;
		}
		case 3:
		{
			f[i] = i - 1;
			insert(i - 1, i);
			o[i][0] = 3;
			o[i][1] = x;
			break;
		}
		case 4:
		{
			f[i] = x;
			insert(x, i);
			break;
		}
		}
	}
	dfs(0);
	for (int i = 1; i <= q; i++)
		printf("%d\n", ans[i]);
}

int main()
{
	freopen("init.in", "r", stdin);
	//freopen("forever.out","w",stdout);
	scanf("%d%d%d", &n, &m, &q);
	solve();
}